<!-- 系统日志-->
<template>
  <div>
    <a-card id="a" :bordered="false">
      <!-- tab 切换日志 start -->
      <a-tabs @change="handleTab">
        <a-tab-pane :tab="tab.tabName" v-for="(tab, index) in tabItem" :key="index">
          <component :is="tab.comp"></component>
        </a-tab-pane>
      </a-tabs>
      <!-- tab 切换日志  end -->
    </a-card>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import SystemLoginLog from './components/SystemLoginLog.vue'
import SystemOperatorLog from './components/SystemOperatorLog.vue'
import SystemExportLog from './components/SystemExportLog.vue'
import ProjectOperatorLog from './components/ProjectOperatorLog.vue'
import ProjectExportLog from './components/ProjectExportLog.vue'

export default {
  name: 'SystemLog',
  data () {
    return {
      statusIndex: 1
    }
  },
  computed: {
    ...mapState({
      project: state => state.user.project
    }),
    tabItem () {
      const systemTabItem = this.getSystemTabByAuth()
      const projectTabItem = this.getProjectTabByAuth()
      return this.project?.id ? projectTabItem : systemTabItem
    }
  },
  components: {
    SystemLoginLog,
    SystemOperatorLog,
    SystemExportLog,
    ProjectExportLog,
    ProjectOperatorLog
  },
  methods: {
    getSystemTabByAuth () {
      let authTab = []
      if (this.$auth('PROJECT.LOGIN_LOG_LIST')) {
        authTab.push(
          { key: 1, tabName: this.$t('all.autotext1525'), comp: 'SystemLoginLog' }
        )
      }
      if (this.$auth('PROJECT.OPERATE_LOG_LIST')) {
        authTab.push(
          { key: 2, tabName: this.$t('all.autotext1267'), comp: 'SystemOperatorLog' }
        )
      }
      if (this.$auth('PROJECT.EXPORT_LOG_LIST')) {
        authTab.push(
          { key: 3, tabName: this.$t('all.autotext752'), comp: 'SystemExportLog' }
        )
      }
      return authTab
    },
    getProjectTabByAuth () {
      let authTab = []
      if (this.$auth('PROJECT.OPERATE_LOG_LIST')) {
        authTab.push(
          { key: 2, tabName: this.$t('all.autotext576'), comp: 'ProjectOperatorLog' }
        )
      }
      if (this.$auth('PROJECT.EXPORT_LOG_LIST')) {
        authTab.push(
          { key: 3, tabName: this.$t('all.autotext1229'), comp: 'ProjectExportLog' }
        )
      }
      return authTab
    },
    // 用于切换状态的
    handleTab (key) {
      this.statusIndex = parseInt(key) + 1
    }
  }
}
</script>
